package com.xxx.client.android.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.xxx.client.android.R;
import com.xxx.client.android.dialog.FeedbackLoadingDialog;
import com.xxx.client.android.util.Tool;

public class FeedbackActivity extends Activity {

	private EditText mFeedbackContent;
	private Button mSubmitButton;
	private Button mBackButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.feedback);

		mSubmitButton = (Button) findViewById(R.id.SubmitButton);
		mBackButton = (Button) findViewById(R.id.BackButton);
		mFeedbackContent = (EditText) findViewById(R.id.FeedbackContent);

		mSubmitButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String text = mFeedbackContent.getText().toString();
				if (text.equals("")) {
					Tool.messageBox(FeedbackActivity.this,
							R.string.feedback_hint_2);
				} else {
					new FeedbackLoadingDialog(FeedbackActivity.this,
							R.string.feedback_loading, R.string.feedback_fail)
							.execute(text);
				}
			}
		});
		mBackButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(FeedbackActivity.this,
						HomeActivity.class);
				startActivity(intent);
			}
		});
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.about, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.about_menu_item:
			Tool.about(this);
			break;
		default:
		}
		return super.onOptionsItemSelected(item);
	}
}
